package com.scada.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.scada.contant.MessageConstants;
import com.scada.hessian.client.impl.UserVisitorClient;
import com.scada.model.bean.User;
import com.scada.model.result.ResponseBean;
import com.scada.service.UserService;


@Service
public class UserServiceImp implements UserService {
	
	@Autowired
	private UserVisitorClient userVisitorClient;

	@Override
	public User securityToLogin(String username, String password) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("username", username);
		return userVisitorClient.findUserByLoginName(map);
	}

	@Override
	public ResponseBean updateState(String uIds, String method) {
		int state = 0;
		if(StringUtils.isNotBlank(method) && 
				StringUtils.equals("delete", method)){
			state = MessageConstants.LoginState.STATE_DEL.getKey();
		}else if(StringUtils.isNotBlank(method) && 
				       StringUtils.equals("disable", method)){
			state = MessageConstants.LoginState.STATE_DISABLE.getKey();
		}else if(StringUtils.isNotBlank(method) && 
			       StringUtils.equals("enable", method)){
			state = MessageConstants.LoginState.STATE_ENABLE.getKey();
		}
		return userVisitorClient.updateState(uIds, state,method);
	}

	@Override
	public ResponseBean updatePassword(String newPad, Integer id) {
		
		return userVisitorClient.updatePassword(newPad, id);
	}

	@Override
	public ResponseBean updateLoginDate(User user) {
		
		return userVisitorClient.updateLoginDate(user);
		
	}
	
}
